// src/models/Comment.ts


import {CommentWithUser} from "@models/CommentWithUser.ts";

export default class Comment {
    commentId?: number
    commentUser!: number  // @CustomNotNull => 非可选
    commentTime?: Date
    fatherComment?: number
    commentRId!: number  // @NotNull => 非可选
    comment!: string
    sumComment?: CommentWithUser[]

    constructor(data?: Partial<Comment>) {
        if (data) {
            this.commentId = data.commentId
            this.commentUser = data.commentUser!
            this.commentTime = data.commentTime ? new Date(data.commentTime) : undefined
            this.fatherComment = data.fatherComment
            this.commentRId = data.commentRId!
            this.comment = (data.comment ?? '').trim()
               this.sumComment = data.sumComment?.map(item => CommentWithUser.from(item)) ?? []
        }
    }

    static from(data: any): Comment {
        return new Comment(data)
    }
}
